#import "SEGSaveorupdateleaseManager.h"

#if __has_include(<Commom/SEGModel.h>)
#import <Commom/SEGModel.h>
#else
#import "SEGModel.h"
#endif
#if __has_include(<Commom/SEGHTTPBusinessManager.h>)
#import <Commom/SEGHTTPBusinessManager.h>
#else
#import "SEGHTTPBusinessManager.h"
#endif

static id _saveOrUpdateLeaseManager;
static dispatch_once_t onceToken;

@implementation SEGSaveorupdateleaseManager
#pragma mark - SINGLE----BEGIN----
+(instancetype)sharedManager{
    dispatch_once(&onceToken, ^{
        _saveOrUpdateLeaseManager = [[self alloc] init];
    });
    return _saveOrUpdateLeaseManager;
}

+(void)destroyResource{
    onceToken = 0;
    _saveOrUpdateLeaseManager = nil;
}

#pragma mark - SINGLE----END----

#pragma mark - HTTP----BEGIN----

/**
 房屋租售-发布出租接口

 @author Sam
 */
-(void)requestSaveorupdateleaseWithParams:(NSDictionary*)params Finished:(void(^)(BOOL isSuccessed,id result,NSString* codeType,NSString* errorMessage))finished{
    
    NSString *urlString = [SEGServerManager serverUrlJoint:kClientRootURL,@"/bms-api/rental/saveOrUpdateLease",nil];
    [SEGHTTPBusinessManager seg_requestJSONWithMethod:POST URLString:urlString parameters:params completed:^(BOOL isSuccessed, id result, NSString *codeType, NSError *error) {
        if (!isSuccessed) {
            finished(isSuccessed,nil,codeType,error.localizedDescription);
            return;
        }
        
        self.saveOrUpdateLease = [SEGSaveorupdateleaseModel yy_modelWithDictionary:result];
        finished(isSuccessed,result,codeType,error.localizedDescription);
        return;
    }];
}


/**
 房屋租售-发布出售接口

 @author Sam
 */
-(void)requestSaveOrUpdateSellWithParams:(NSDictionary*)params Finished:(void(^)(BOOL isSuccessed,id result,NSString* codeType,NSString* errorMessage))finished{
    
    NSString *urlString = [SEGServerManager serverUrlJoint:kClientRootURL,@"/bms-api/rental/saveOrUpdateSell",nil];
    [SEGHTTPBusinessManager seg_requestJSONWithMethod:POST URLString:urlString parameters:params completed:^(BOOL isSuccessed, id result, NSString *codeType, NSError *error) {
        if (!isSuccessed) {
            finished(isSuccessed,nil,codeType,error.localizedDescription);
            return;
        }
        
        self.saveOrUpdateLease = [SEGSaveorupdateleaseModel yy_modelWithDictionary:result];
        finished(isSuccessed,result,codeType,error.localizedDescription);
        return;
    }];
}

-(void)requestPulishEditWithParams:(NSDictionary*)params Finished:(void(^)(BOOL isSuccessed,id result,NSString* codeType,NSString* errorMessage))finished {
    NSString *urlString = [SEGServerManager serverUrlJoint:kClientRootURL,@"/bms-api/parking/saveOrUpdateRental",nil];
    [SEGHTTPBusinessManager seg_requestJSONWithMethod:POST URLString:urlString parameters:params completed:^(BOOL isSuccessed, id result, NSString *codeType, NSError *error) {
        if (!isSuccessed) {
            finished(isSuccessed,nil,codeType,error.localizedDescription);
            return;
        }
        finished(isSuccessed,result,codeType,error.localizedDescription);
        return;
    }];
}


#pragma mark - HTTP----END----

#pragma mark - GETTER----BEGIN----
-(SEGSaveorupdateleaseModel *)saveOrUpdateLease{
    if (!_saveOrUpdateLease) {
        _saveOrUpdateLease = [[SEGSaveorupdateleaseModel alloc]init];
    }
    return _saveOrUpdateLease;
}
#pragma mark - GETTER----END----
@end

